package com.birdy.ws.map;

import org.springframework.stereotype.Component;

import javax.websocket.Session;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author birdy
 * @date 2022/4/13 3:01 PM
 */
@Component
public class UserSessionMap {
    private static final Map<String, Session> userSessionMap = new ConcurrentHashMap<>();

    public static void addUserSession(String userId, Session session) {
        userSessionMap.put(userId, session);
    }

    public static Session getSession(String userId) {
        return userSessionMap.get(userId);
    }

    public static void removeSession(String userId) {
        userSessionMap.remove(userId);
    }
    // 获取userSessionMap
    public static Map<String, Session> getUserSessionMap() {
        return userSessionMap;
    }
    // 获取map大小
    public static int getUserSessionMapSize() {
        return userSessionMap.size();
    }
}
